package com.zy.nft_system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zy.nft_system.domain.Announcement;
import com.zy.nft_system.domain.Result;
import com.zy.nft_system.service.AnnouncementService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 这是那头猪？
 * @version 1.0
 * @description: TODO
 * @date 2022/12/16 15:24
 */
@RestController
@RequestMapping("/Announcement")
@Slf4j
public class AnnouncementController {
    @Autowired
    AnnouncementService announcementService;

    @GetMapping("/queryAnnouncementList")
    public Result queryAnnouncementList(){
        log.info("正在查询公告");
        Announcement announcement = announcementService.getById(1);
        log.info("查询成功");
        return Result.success("查询成功", announcement);
    }
    @PostMapping("/updateAnnouncement")
    public Result updateAnnouncement(@RequestBody Announcement announcement){
        log.info("正在修改公告");
        if (!announcementService.update(announcement, new QueryWrapper<Announcement>().eq("id", announcement.getId()))) {
            log.info("修改失败");
            return Result.error("修改失败");
        }
        log.info("修改成功");
        return Result.success("修改成功", announcement);
    }
}
